package com.xiaoyu.izf.controller;

import com.xiaoyu.izf.aspect.RequestAuth;
import com.xiaoyu.izf.model.UserInfo;
import com.xiaoyu.izf.model.page.DataTableBean;
import com.xiaoyu.izf.model.page.ParamListBean;
import com.xiaoyu.izf.service.YqfStoreStatsService;
import com.xiaoyu.izf.util.DateTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 商户流水统计
 */

@Controller
@RequestMapping("/bmc/stats")
public class BMCStatsController extends BaseController{

    @Autowired
    private YqfStoreStatsService yqfStoreStatsService;

    /**
     * 直推本区域内商户流水：服务商
     * @param model
     * @return
     */
    @RequestMapping("/par_direct_merchant_in_list_page")
    @RequestAuth
    public String parDirectMerchantInListPage(Model model) {
        String today = DateTimeUtil.getDate2Str();
        String timeFrame = today.substring(0,8)+"01至"+today;
        model.addAttribute("timeFrame",timeFrame);
        return "/mgr/bmc_stats/par_direct_merchant_in_list";
    }
    @RequestMapping("/par_direct_merchant_list_in")
    @ResponseBody
    @RequestAuth
    public DataTableBean parDirectMerchantListIn(HttpServletRequest request, @RequestBody String body) {
        UserInfo user = user(request);
        ParamListBean paramListBean = getParamListBean(body);
        DataTableBean dataTableBean = yqfStoreStatsService.parDirectMerchantForList(paramListBean,user,true);
        return dataTableBean;
    }

    /**
     * 直推本区域外商户流水：服务商
     * @param model
     * @return
     */
    @RequestMapping("/par_direct_merchant_out_list_page")
    @RequestAuth
    public String parDirectMerchantOutListPage(Model model) {
        String today = DateTimeUtil.getDate2Str();
        String timeFrame = today.substring(0,8)+"01至"+today;
        model.addAttribute("timeFrame",timeFrame);
        return "/mgr/bmc_stats/par_direct_merchant_out_list";
    }
    @RequestMapping("/par_direct_merchant_list_out")
    @ResponseBody
    @RequestAuth
    public DataTableBean parDirectMerchantListOut(HttpServletRequest request, @RequestBody String body) {
        UserInfo user = user(request);
        ParamListBean paramListBean = getParamListBean(body);
        DataTableBean dataTableBean = yqfStoreStatsService.parDirectMerchantForList(paramListBean,user,false);
        return dataTableBean;
    }

    /**
     * 直推商户流水：一、二、三级合伙人
     * @param model
     * @return
     */
    @RequestMapping("/par_direct_merchant_list_page")
    @RequestAuth
    public String parDirectMerchantListPage(Model model) {
        String today = DateTimeUtil.getDate2Str();
        String timeFrame = today.substring(0,8)+"01至"+today;
        model.addAttribute("timeFrame",timeFrame);
        return "/mgr/bmc_stats/par_direct_merchant_list";
    }
    @RequestMapping("/par_direct_merchant_list")
    @ResponseBody
    @RequestAuth
    public DataTableBean parDirectMerchantList(HttpServletRequest request, @RequestBody String body) {
        UserInfo user = user(request);
        ParamListBean paramListBean = getParamListBean(body);
        DataTableBean dataTableBean = yqfStoreStatsService.parDirectMerchantForList(paramListBean,user,false);
        return dataTableBean;
    }

    /**
     * 本区域内非直推商户流水：服务商
     * @param model
     * @return
     */
    @RequestMapping("/par_region_merchant_list_page")
    @RequestAuth
    public String parRegionMerchantListPage(Model model) {
        String today = DateTimeUtil.getDate2Str();
        String timeFrame = today.substring(0,8)+"01至"+today;
        model.addAttribute("timeFrame",timeFrame);
        return "/mgr/bmc_stats/par_region_merchant_list";
    }
    @RequestMapping("/par_region_merchant_list")
    @ResponseBody
    @RequestAuth
    public DataTableBean parRegionMerchantList(HttpServletRequest request, @RequestBody String body) {
        UserInfo user = user(request);
        ParamListBean paramListBean = getParamListBean(body);
        DataTableBean dataTableBean = yqfStoreStatsService.parRegionMerchantForList(paramListBean,user);
        return dataTableBean;
    }

    /**
     * 间推商户流水：服务商、一级合伙人
     * @param model
     * @return
     */
    @RequestMapping("/par_indirect_merchant_list_page")
    @RequestAuth
    public String parIndirectMerchantListPage(Model model) {
        String today = DateTimeUtil.getDate2Str();
        String timeFrame = today.substring(0,8)+"01至"+today;
        model.addAttribute("timeFrame",timeFrame);
        return "/mgr/bmc_stats/par_indirect_merchant_list";
    }
    @RequestMapping("/par_indirect_merchant_list")
    @ResponseBody
    @RequestAuth
    public DataTableBean parIndirectMerchantList(HttpServletRequest request, @RequestBody String body) {
        UserInfo user = user(request);
        ParamListBean paramListBean = getParamListBean(body);
        DataTableBean dataTableBean = yqfStoreStatsService.parIndirectMerchantForList(paramListBean,user);
        return dataTableBean;
    }

}
